home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11679 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.mindspring.com!usenet
  2. From: rudd@mindspring.com (Justin Rudd)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ Shortcomings ?
  5. Date: Fri, 15 Mar 1996 17:32:09 GMT
  6. Organization: MindSpring Enterprises
  7. Message-ID: <4ic9kj$lj6@B1FF.mindspring.com>
  8. References: <31488E8D.167E@aw.sgi.com> <4iaqch$moh@B1FF.mindspring.com> <31493CDA.41C6@aw.sgi.com>
  9. Reply-To: rudd@mindspring.com
  10. NNTP-Posting-Host: rudd.mindspring.com
  11. X-Newsreader: Forte Free Agent v0.55
  12.  
  13. OK...this clears it up a bit.  
  14.  
  15. Justin
  16.  
  17. >No.
  18.  
  19. >I guess my post was messy and unclear.
  20. >What I want is to be able for a class A to tell:
  21.  
  22.  
  23. >class A
  24. >{
  25. >restricted B:
  26. >    void    DoSomething();
  27. >}
  28.  
  29. >This means: Ok, the method A::DoSomething is public, but not
  30. >public for everybody. Only members of class B can have access to
  31. >this method.
  32.  
  33. >It's a bit like the friend operator, but instead of spilling
  34. >everything to the friend, we just let him peep through a specialized window.
  35.  
  36.  
  37. >No.
  38.  
  39. >What I meant was: I would like to be able to redefine the default
  40. >copy constructor for pointers.
  41.  
  42. >In other words, when I write:
  43. >class A
  44. >{
  45. >};
  46.  
  47. >main()
  48. >{
  49. >    A    *a;
  50. >    B    *b;
  51.  
  52. >    a=new A();
  53. >    b=a;
  54. >}
  55.  
  56. >I want the compiler to trap this for me and give me control.
  57. >What I really want the compiler to do is:
  58.  
  59. >main()
  60. >{
  61. >    1. Call the constructor of object A* (that's what we do. We build an A*)
  62. >    2. Call the constructor of object B*
  63.  
  64. >    Call the constructor for object A* (to temporarily store the result of new)
  65. >    Call the assignment method (to assign the result of new to a)
  66. >    Call the assignment operator (to assign the value of a to b)
  67. >    
  68. >}
  69.  
  70. >Another way to put it:
  71. >I would like to be able to write
  72.  
  73. >class A*
  74. >{
  75. >    A*();        // To build a pointer to A
  76. >    A*(const A*&)    // To build an A* from another A*
  77. >    ~A*();        // To get hold of what happens when a pointer to A goes out of scope
  78.  
  79. >    A* operator=(const A*&);    // To redefine assignment
  80. >    
  81. >}
  82.  
  83.  
  84. >All this complicated mechanics would allow to build
  85. >industrial-strength reference counting on objects.
  86.  
  87. >    - Mgix
  88.  
  89.  
  90.